/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Bean.Usuario;
import java.util.List;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import util.JPAUtil;

/**
 *
 * @author alexandre
 */
@Stateless(name = "UsuarioDAO")
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class UsuarioDAO {
    @PersistenceContext(name = "PersistenceUnit")
    private EntityManager em;
    @Resource
    private SessionContext context;
    
    
    public void add(Usuario user){
       // EntityManager em = JPAUtil.getInstance().getEntityManager();
        em.persist(user);
    }
    
    public void edit(Usuario user){
        em.merge(user);
    }
    
    public void del(Usuario user){
        em.remove(user);
    }
    
    public List<Usuario> getAllUsers(){
        Query query = em.createQuery("select user from Usuario user");
        
        return query.getResultList();
        
    }
    
}
